package bb.lanxing.activity.base

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.viewbinding.ViewBinding

abstract class BaseActivityViewBinding<T : ViewBinding> : BaseCommonActivity() {
    protected lateinit var mViewBinding: T

    // default is Log.INFO, if make debug true
    // adb shell setprop log.tag.TAG D , restart app
    @JvmField
    protected var debug = Log.isLoggable(TAG, Log.DEBUG)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (debug) {
            log("BaseActivityViewBinding onCreate!")
        }
        mViewBinding = getViewBinding()
        setContentView(mViewBinding.root)
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)

        initView()
        initData()
        loadData()
    }

    protected fun log(content: String) {
        Log.d(TAG, content)
    }

    protected abstract fun getViewBinding(): T

    companion object {
        private const val TAG = "dynamic_debug"
    }

    //must use layout id to avoid it not used
    protected abstract fun getLayout(): Int
}